<html>
<head><meta charset="utf-8"><title>Parent fn of closure · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html">Parent fn of closure</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239902563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Parent%20fn%20of%20closure/near/239902563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html#239902563">(May 22 2021 at 21:48)</a>:</h4>
<p>Is there an easy way to get the <code>DefId</code> of the (non-closure) parent of a closure? Do I just have to iterate over the parent nodes?</p>



<a name="239902705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Parent%20fn%20of%20closure/near/239902705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html#239902705">(May 22 2021 at 21:51)</a>:</h4>
<p>Just as an example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">baz</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">{};</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Let's say that I have the <code>HirId</code> of <code>baz</code>, how would I get the <code>HirId</code>/<code>LocalDefId</code> of <code>foo</code>?</p>



<a name="239902994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Parent%20fn%20of%20closure/near/239902994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html#239902994">(May 22 2021 at 21:56)</a>:</h4>
<p>Can I just take <code>closure_hir_id.owner</code>?</p>



<a name="239903118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Parent%20fn%20of%20closure/near/239903118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html#239903118">(May 22 2021 at 21:58)</a>:</h4>
<p>I think yes, but I need to make sure.</p>



<a name="239903162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Parent%20fn%20of%20closure/near/239903162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html#239903162">(May 22 2021 at 21:59)</a>:</h4>
<p>Yes, <code>closure_hir_id.owner</code> should be right.</p>



<a name="239903210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Parent%20fn%20of%20closure/near/239903210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Parent.20fn.20of.20closure.html#239903210">(May 22 2021 at 22:00)</a>:</h4>
<p>Ok, thank you</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>